//
//  DYJiangjieDetailView.swift
//  SheYangBigData
//
//  Created by 宋海胜 on 2021/1/5.
//  Copyright © 2021 叁拾叁. All rights reserved.
//

import UIKit
import YYText
import SDCycleScrollView

class DYJiangjieDetailView: SYBaseView {
    
    public var bgView:UIScrollView = UIScrollView()
    let cycleScrollView: SDCycleScrollView = SDCycleScrollView(frame: CGRect.zero)
    
    let titleLb: UILabel = {
        let v:UILabel = UILabel()
        v.textColor = UIColor.white
        v.font = 18.autoBoldFontSize()
        
        v.textAlignment = .center
        return v
    }()
    
    let back: UIButton = {
        let v: UIButton  = UIButton()
        v.setImage(UIImage(named: "jiangjie_xia"), for: .normal)
        return v
    }()
    
    
    let textView: UITextView = {
        let v: UITextView = UITextView()

        v.font = 13.autoFontSize()
//        v.textColor = .white
        v.backgroundColor = .clear

        return v
    }()
    
    func configure(_ model: DYJQJIangjieListModel) {
        
        //通过富文本来设置行间距
        let  paraph =  NSMutableParagraphStyle ()
        //将行间距设置为28
        paraph.lineSpacing = 6
        //样式属性集合
        let  attributes = [ NSAttributedString.Key.font : UIFont .systemFont(ofSize: 13),NSAttributedString.Key.paragraphStyle : paraph, NSAttributedString.Key.foregroundColor : UIColor.white]
        textView.attributedText =  NSAttributedString (string: model.content ?? "", attributes: attributes)
        
        titleLb.text = model.title
        cycleScrollView.imageURLStringsGroup = [IMGIP + (model.imgUrl ?? "")]
        
    }
    
    override func initViews() {
        
        back.addAction {[weak self] in
            if let `self` = self {
                
                self.clickedClosure?(0)
            }
        }
        self.backgroundColor = UIColor(white: 0, alpha: 0.85)
        bgView.frame = CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: SCREEN_HEIGHT - BOTTOM_SAFE_HEIGHT)
        bgView.contentSize = bgView.frame.size
        
        bgView.showsVerticalScrollIndicator = false
        bgView.showsHorizontalScrollIndicator = false
        self.addSubview(bgView)
        cycleView()
        
        bgView.addSubview(titleLb)
        bgView.addSubview(textView)
        bgView.addSubview(back)
        titleLb.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(55.0.autoWidth())
            make.centerX.equalToSuperview()
            make.height.equalTo(17.0.autoWidth())
        }
        back.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(61.0.autoWidth())
            make.left.equalToSuperview().offset(16.0.autoWidth())
            make.height.equalTo(8.0.autoWidth())
            make.width.equalTo(14.0.autoWidth())
        }
        cycleScrollView.snp.makeConstraints { (make) in
            make.top.equalTo(titleLb.snp.bottom).offset(47.0.autoWidth())
            make.centerX.equalToSuperview()
            make.width.equalTo(250.0.autoWidth())
            make.height.equalTo(188.0.autoWidth())
        }
        textView.snp.makeConstraints { (make) in
            make.top.equalTo(cycleScrollView.snp.bottom).offset(30.0.autoWidth())
            make.centerX.equalToSuperview()
            make.left.equalToSuperview().offset(autoWidth(20.0))
            make.right.equalTo(self).offset(autoWidth(-20.0))
            make.height.equalTo(274.0.autoWidth())
        }
    }
    
    func cycleView() {
        
        
        //        cycleScrollView.placeholderImage = UIImage(named: "banner")
        // 添加到view
        cycleScrollView.layer.cornerRadius = 5
        cycleScrollView.layer.masksToBounds = true
        bgView.addSubview(cycleScrollView)
        
    }
    
    
}
